//
//  SLLogDeleteAlertView.m
//  SlockApp
//
//  Created by 凯朱 on 2024/7/25.
//

#import "SLLogDeleteAlertView.h"
@interface SLLogDeleteAlertView(){
    NSInteger _curIndex;
}

@end
@implementation SLLogDeleteAlertView
-(void)awakeFromNib{
    [super awakeFromNib];
    _curIndex = 1;
    _bgView.layer.cornerRadius = 10;
    _bgView.layer.masksToBounds = YES;
    
    _listBgView.layer.cornerRadius = 20;
    _listBgView.layer.masksToBounds = YES;
    
    [_deleteBtn setTitle:kLocalString(@"Delete") forState:UIControlStateNormal];
    _deleteBtn.btnStyle = 1;
    _tipLbl.text = kLocalString(@"Delete logs");
    _list.layer.cornerRadius = 2;
    _list.layer.masksToBounds = YES;
    _listLbl1.text = kLocalString(@"Today");
    _listLbl2.text = kLocalString(@"One week");
    _listLbl3.text = kLocalString(@"One month");
    _listLbl4.text = kLocalString(@"All");
    _icon1.hidden = NO;
    _listLbl1.textColor = KColor_O;
    
    _icon2.hidden = _icon3.hidden = _icon4.hidden = YES;
    _listLbl2.textColor = _listLbl3.textColor = _listLbl4.textColor = KWhiteColor_text;
    
    kWeakSelf(self);
    _listView1.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakself changeTime:1];
    }];
    [_listView1 addGestureRecognizer:tap1];
    
    _listView2.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakself changeTime:2];
    }];
    [_listView2 addGestureRecognizer:tap2];
    
    _listView3.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakself changeTime:3];
    }];
    [_listView3 addGestureRecognizer:tap3];
    
    _listView4.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakself changeTime:4];
    }];
    [_listView4 addGestureRecognizer:tap4];
    
    _grayView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        [weakself removeWithAnimation];
    }];
    [_grayView addGestureRecognizer:tap5];
    
    _hideView.userInteractionEnabled = YES;
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeDown:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionDown;
    [_hideView addGestureRecognizer:swipeRight];
}

// 手势处理方法
-(void)handleSwipeDown:(UISwipeGestureRecognizer *)gesture {
    [self removeWithAnimation];

}

-(void)changeTime:(NSInteger)index{
    if (_curIndex == index) {
        return;
    }
    _curIndex = index;
    _listLbl1.textColor = _curIndex == 1 ? KColor_O : KWhiteColor_text;
    _listLbl2.textColor = _curIndex == 2 ? KColor_O : KWhiteColor_text;
    _listLbl3.textColor = _curIndex == 3 ? KColor_O : KWhiteColor_text;
    _listLbl4.textColor = _curIndex == 4 ? KColor_O : KWhiteColor_text;
    _icon1.hidden = _curIndex != 1;
    _icon2.hidden = _curIndex != 2;
    _icon3.hidden = _curIndex != 3;
    _icon4.hidden = _curIndex != 4;
}


- (IBAction)deleteAction:(id)sender {
    [self removeWithAnimation];
    if (self.btnBlock) {
        self.btnBlock(_curIndex);
    }
}


@end
